package com.yupi.springbootinit.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yupi.springbootinit.enums.SearchKeyWord;
import com.yupi.springbootinit.register.SearchRegisterService;
import com.yupi.springbootinit.service.UserSearchService;
import com.yupi.springbootinit.service.impl.search.PictureSearchService;
import com.yupi.springbootinit.service.impl.search.PostSearchService;
import com.yupi.springbootinit.service.impl.search.SearchService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;

@Service
public class SearchServiceImpl implements UserSearchService {

    @Resource
    private SearchRegisterService searchRegisterService;


    @Override
    public <T extends Serializable> Page<T> search(String searchText, SearchKeyWord keyWord, int pageSize, int pageNo) {
        SearchService<?> searchService = searchRegisterService.getSearchService(keyWord);
        if (searchService == null) return null;
        return (Page<T>) searchService.doSearch(searchText, pageSize, pageNo);
    }
}
